﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="ThietBiSo.LinQDB" %>
<%@ Import Namespace="ThietBiSo.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Website - bảng điều khiển
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
     
        TinTuc tt = (TinTuc)ViewData["tintucs"];

        MLoaiTinTuc mldm = new MLoaiTinTuc();
        var loaidm = mldm.FindAll_Web();
       // int maloaitin = int.Parse(Request.QueryString["cbNhom"]);
    %>
    <script type="text/javascript">
        function submitForm() {
            if (checkForm()) {
                document.forms[0].submit();
            }
        }
        function submitForm1() {

            document.forms[0].submit();

        }
        function checkForm() {
            var flag = true;
            var F = document.forms[0];
            var TieuDe = document.getElementById("TieuDe").value;
            var NDTT = document.getElementById("NoiDungTomTat").value;


            if (TieuDe == null || TieuDe == "") {
                alert("Chưa nhập tiêu đề tin");
                F.TieuDe.focus();
                flag = false;

            }
            else if (NDTT == null || NDTT == "") {
                alert("Chưa nhập tóm tắt tin");
                F.NoiDungTomTat.focus();
                flag = false;

            }
            return flag;
        }
    </script>
    <% using (Html.BeginForm("Edit", "TinTuc", FormMethod.Post, new { @enctype = "multipart/form-data" }))
       { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend class="classFieldSet">Sửa tin tức</legend>
        <table width="100%">
            <tr style="background-color: #e0e0e0">
                <td class="classCreate">
                   
                    <input type="button" value="Lưu" class="btn" onclick="submitForm();" />
                  
                </td>
                <td class="classBack">
                    <%: Html.ActionLink("Quay lại", "tintuc", new { cbNhom = ViewData["urlcbNhom"] })%>
                </td>
            </tr>
          <%--  <tr>
                <td class="tableLabel">
                    Danh mục tin tức
                </td>
                <td style="color: Red; font-weight: bold;">
                    <%:Html.Hidden("cbNhom",ViewData["urlcbNhom"])%>
                  
                    <%: Html.DropDownList("ddlMaLoaiTT", new SelectList(loaidm, "MaLoaiTinTuc", "TenLoaiTinTuc", tt.MaLoaiTinTuc), "Chọn danh mục tin", new { @style = "width:606px;" })%>
                </td>
            </tr>--%>
      
            <tr>
                <td class="tableLabel">
                    Tiêu đề
                </td>
                <td class="tableField">
                    <%:Html.TextBox("TieuDe", tt.TieuDe, new { @style = "width:600px" })%>
                </td>
            </tr>
            <tr>
                <td class="tableLabel">
                    Tóm tắt
                </td>
                <td class="tableField">
                    <%:Html.TextArea("NoiDungTomTat", tt.NoiDungTomTat, new { @style = "width:600px ; height=100px" })%>
                </td>
            </tr>
            <tr>
                <td class="">
                    Hình
                </td>
                <td class="">
                    <%: Html.Hidden("HiddenHinhAnh", tt.UrlHinh)%>
                    <table width="100%">
                        <tr>
                            <td>
                                <%:Html.TextBox("HinhAnh", tt.UrlHinh)%>
                                <input type="button" value="Chọn ..." id="btnSelectImg" name="btnSelectImg" />
                                <script type="text/javascript">
                                    $(document).ready(function () {
                                        $("#btnSelectImg").click(function () {
                                            var finder = new CKFinder();
                                            finder.selectActionFunction = function (fileUrl) {
                                                $('#HinhAnh').val(fileUrl);
                                            };
                                            finder.popup();
                                        });
                                    });
                                </script>
                                <%--  <input class="field" type="file" name="fileUpload" id="fileUpload" />--%>
                                <%-- <div style="color: Red">
                                    Kích thước hình: (160 x 110) là tốt nhất</div>--%>
                            </td>
                            <td>
                                <%if (tt.UrlHinh == "" || tt.UrlHinh == null || tt.UrlHinh == "noImage")
                                  {%>
                                <img src="<%:Url.Content("~/Content/images/nophoto.gif")%>" alt="" width="150px;"
                                    height="80px;" />
                                <%}
                                  else
                                  { %>
                                <img src="<%: tt.UrlHinh%>" alt="" width="150px" height="80px" />
                                <%} %>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="tableLabel">
                    Thứ tự
                </td>
                <td class="tableField">
                    <%:Html.TextBox("ThuTu", tt.ThuTu)%>
                </td>
            </tr>
           
        </table>
        <div>
            <%= Html.TextArea("ChiTiet", System.Net.WebUtility.HtmlDecode(tt.ChiTiet))%>
            <script type="text/javascript">

                CKEDITOR.replace('ChiTiet',
             {
                 htmlEncodeOutput: true,
                 enterMode: CKEDITOR.ENTER_BR,
                 filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?type=Images',
                 filebrowserImageUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'
             });
          
            </script>
        </div>
    </fieldset>
    <% } %>
</asp:Content>
